<?php namespace Common\Model;

use Hdphp\Model\Model;
class Link extends Model
{
	//写入表
	protected $table = "link";
	//自动验证
	protected $validate =array(
		array('lname',"required","请输入名称",3,3),
		array('lname',"max_en","最多输入10个字符",3,3),
		array('url',"http","请输入网址",3,3),
		array('sort',"num:20,88888","请输入数字",3,3),
		
	);
	//自定义完成
	//array(表单字段名,处理方法,方法类型,验证条件,处理时间) 
	protected $auto = array(
		array("addtime","time","function",3,3),
		array("logo","image","method",3,3),
	);
	
	public function image()
	{
		/*创建上传的路径*/
		$path = "Logo/" . date("ymd");
		$file = Upload::type('jpg,png,txt')->path($path)->size(2000000)->make();
		var_dump($_FILES);
		
		
		//如果有照片上传
		if($file)
		{
			//缩略图片
			$logoPath = Image::thumb($file[0]['path'],$path ."/logo_" .$file[0]['basename'],200,200,5);
			return $logoPath;
			
		}else{
			return "";
		}
	}
	
	
		
	//友情链接添加
	public function addLink()
	{
		
		//自动验证
		if(!$this->create()) return false;
		$this->add();
		return true;
	}
	
	/*编辑*/
	public function edit()
	{
		//自动验证
		if(!$this->create()) return false;
		
		/*上传的错误信息*/
		if(isset($_FILES['logo']) && $_FILES['logo']['error'] !=4 )
		{
			//上传错误信息
			if($error = Upload::getError())
			{
				$this->error = $error;
				return false;
			}
			
		}
		$this->save();
		
		return true;
		
	}
	//删除
	public function del()
	{
		
	}
	
}


























